package cn.source.zk.service.impl;

import cn.source.common.core.domain.entity.SysRole;
import cn.source.common.core.domain.entity.SysUser;
import cn.source.common.utils.SecurityUtils;
import cn.source.system.mapper.SysRoleMapper;
import cn.source.system.mapper.SysUserMapper;
import cn.source.zk.domain.entity.SimCard;
import cn.source.zk.domain.vo.SimSortVO;
import cn.source.zk.mapper.ZkSimCardMapper;
import cn.source.zk.service.IZkSimCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ZkSimCardServiceImpl implements IZkSimCardService {

    @Autowired
    private ZkSimCardMapper simCardMapper;

    @Autowired
    private SysRoleMapper roleMapper;

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询sim卡分页列表
     * @param simCard
     * @return
     */
    @Override
    public List<SimCard> listPage(SimCard simCard) {
        return simCardMapper.selectListPage(simCard,SecurityUtils.getUserId());
    }

    @Override
    public List<SimCard> selectExpiredSimCard() {
        return simCardMapper.selectExpiredSimCard();
    }

    /**
     * 新增sim卡
     * @param simCard
     * @return
     */
    public int save(SimCard simCard) {
        return simCardMapper.save(simCard);
    }

    /**
     * 根据num获取sim卡信息
     * @param num
     * @return
     */
    public SimCard getByNum(Long num) {
        SimCard simCard = new SimCard();
        simCard.setNum(num);
        return simCardMapper.selectListPage(simCard,SecurityUtils.getUserId()).get(0);
    }

    /**
     * 修改sim卡信息
     * @param simCard
     * @return
     */
    public int edit(SimCard simCard) {

        return simCardMapper.edit(simCard);
    }

    /**
     * 批量删除
     * @param nums
     * @return
     */
    public int removeBatch(List<Long> nums) {
        return simCardMapper.removeBatch(nums);
    }

    /**
     * 检查sim卡是否存在
     * @param phone
     * @return
     */
    public boolean checkSimCard(String phone,Long num) {
        SimCard simCard = new SimCard();
        simCard.setPhone(phone);
        simCard.setNum(num);

        int result = simCardMapper.checkSimCard(simCard);
        return result > 0;
    }

    /**
     * 获取sim顺序
     * @return
     */
    public List<SimSortVO> getSimSortList() {

        return simCardMapper.getSimSortList();

    }

    /**
     * 获取到期数据15天
     * @return
     */
    public List<SimCard> getExpiringData() {

        return simCardMapper.getExpiringData();
    }
}
